package com.ktjy.ruoyidata.service.impl;

import java.util.List;
import java.util.Random;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktjy.ruoyidata.mapper.MyWorkstationMapper;
import com.ktjy.ruoyidata.domain.MyWorkstation;
import com.ktjy.ruoyidata.service.IMyWorkstationService;

/**
 * 工作站Service业务层处理
 *
 * @author t382
 * @date 2025-05-07
 */
@Service
public class MyWorkstationServiceImpl implements IMyWorkstationService {
    @Autowired
    private MyWorkstationMapper myWorkstationMapper;

    /**
     * 查询工作站
     *
     * @param workstationId 工作站主键
     * @return 工作站
     */
    @Override
    public MyWorkstation selectMyWorkstationByWorkstationId(Long workstationId) {
        return myWorkstationMapper.selectMyWorkstationByWorkstationId(workstationId);
    }

    /**
     * 查询工作站列表
     *
     * @param myWorkstation 工作站
     * @return 工作站
     */
    @Override
    public List<MyWorkstation> selectMyWorkstationList(MyWorkstation myWorkstation) {
        return myWorkstationMapper.selectMyWorkstationList(myWorkstation);
    }

    /**
     * 新增工作站
     *
     * @param myWorkstation 工作站
     * @return 结果
     */
    @Override
    public int insertMyWorkstation(MyWorkstation myWorkstation) {
        // 生成车间编码
        String prefix = "WS"; // 默认

        // 生成3位随机数
        String randomPart = String.format("%04d", new Random().nextInt(10000));
        String clientCode = prefix + randomPart;
        myWorkstation.setWorkstationCode(clientCode);
        myWorkstation.setCreateTime(DateUtils.getNowDate());
        return myWorkstationMapper.insertMyWorkstation(myWorkstation);
    }

    /**
     * 修改工作站
     *
     * @param myWorkstation 工作站
     * @return 结果
     */
    @Override
    public int updateMyWorkstation(MyWorkstation myWorkstation) {
        myWorkstation.setUpdateTime(DateUtils.getNowDate());
        return myWorkstationMapper.updateMyWorkstation(myWorkstation);
    }

    /**
     * 批量删除工作站
     *
     * @param workstationIds 需要删除的工作站主键
     * @return 结果
     */
    @Override
    public int deleteMyWorkstationByWorkstationIds(Long[] workstationIds) {
        return myWorkstationMapper.deleteMyWorkstationByWorkstationIds(workstationIds);
    }

    /**
     * 删除工作站信息
     *
     * @param workstationId 工作站主键
     * @return 结果
     */
    @Override
    public int deleteMyWorkstationByWorkstationId(Long workstationId) {
        return myWorkstationMapper.deleteMyWorkstationByWorkstationId(workstationId);
    }
}
